package com.fanhao.dllo.soundfm.application;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.v4.app.Fragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/7.
 */
public class BaseApplication extends Application {
    private static Context context;
    private static List<Activity> activities;
    private static List<Fragment> fragments;


    @Override
    public void onCreate() {
        super.onCreate();
        context = this;
    }


    /**
     * 为其他类获得Application里的context
     **/
    public static Context getContext() {
        return context;
    }

    /**
     * 向List<Activity>中加入新的activity
     **/
    private static void addActivity(Activity activity) {
        if (activities == null) {
            activities = new ArrayList<>();
        }
        activities.add(activity);
    }

    /**
     * 移除activity
     **/
    private static void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    /**
     * 销毁所有activity
     **/
    private static void finishAll() {
        // 遍历集合,将所有的Activity finish
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
    }
}
